package cn.player.download.db;

import android.content.Context;

import cn.player.download.DownloadInfo;


public class DbManager {
    private static DbManager sDbManager;
    private final DownloadInfoDao mDownloadInfoDao;

    public static DbManager getInstance(Context context) {
        if (sDbManager == null) {
            synchronized (DbManager.class){
                sDbManager = new DbManager(context.getApplicationContext());
            }
        }
        return sDbManager;
    }

    private DbManager(Context context) {
        mDownloadInfoDao = new DownloadInfoDao(context.getApplicationContext());
    }

    public synchronized void insert(DownloadInfo downloadInfo) {
        mDownloadInfoDao.insert(downloadInfo);
    }

    public synchronized void delete(String vid) {
        mDownloadInfoDao.delete(vid);
    }

    public synchronized void update(String vid, int downloadState) {
        mDownloadInfoDao.update(vid, downloadState);
    }
    public synchronized void update(String vid, int progress, int downloadState) {
        mDownloadInfoDao.update(vid, progress, downloadState);
    }

    public synchronized void update(String vid, int downloadState, String targetFilePath) {
        mDownloadInfoDao.update(vid, downloadState, targetFilePath);
    }

    public synchronized DownloadInfo find(String vid) {
        return mDownloadInfoDao.find(vid);
    }


    public boolean exists(String tag) {
        return mDownloadInfoDao.exists(tag);
    }
}
